﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataAccessLayer
{
    public class SupplierDataAccess
    {
        StationeryInventoryEntities1 r = new StationeryInventoryEntities1();
        public List<string> getSupplierid()
        {
            List<string> idlist = new List<string>();
            var x = from s in r.Suppliers
                    select s.SupplierID;
            idlist = x.ToList<string>();

            return idlist;

        }

        public bool savesupplier(String SupplierID, String Suppliername, String ContactName, String Phoneno, String Faxno, String GSTregno, String address, String email)
        {
            bool ans = false;
            Supplier sup = new Supplier();
            sup.SupplierID = SupplierID;
            sup.SupplierName = Suppliername;
            sup.ContactName = ContactName;
            sup.PhoneNo = Convert.ToInt32(Phoneno);
            sup.FaxNo = Convert.ToInt32(Faxno);
            sup.GSTRegNo = GSTregno;
            sup.Address = address;
            sup.Email = email;
            try
            {
                r.Suppliers.Add(sup);
                r.SaveChanges();
                ans = true;
            }
            catch (Exception ex)
            {
                ans = false;

            }
            return ans;



        }

        public List<object> category_search(string search)
        {
            List<object> stationerylist = new List<object>();

            StationeryInventoryEntities1 se = new StationeryInventoryEntities1();
            var q = from st in se.Stationeries
                    join c in se.Categories on st.CategoryID equals c.CategoryID
                    where c.CategoryName == search
                    select new { st.ItemCode, c.CategoryName, st.ItemName, st.ReorderLevel, st.ReorderQty, st.UOM, st.AvailableQty };
            stationerylist = q.ToList<object>();
            return stationerylist;



        }

        public List<object> category_searchall()
        {
            List<object> stationerylist = new List<object>();

            StationeryInventoryEntities1 se = new StationeryInventoryEntities1();
            var q = from st in se.Stationeries
                    join c in se.Categories on st.CategoryID equals c.CategoryID
                    select new { st.ItemCode, c.CategoryName, st.ItemName, st.ReorderLevel, st.ReorderQty, st.UOM, st.AvailableQty };
            stationerylist = q.ToList<object>();
            return stationerylist;
        }

        public List<Object> getcategory()
        {
            List<object> categories = new List<object>();
            var q = from x in r.Categories
                    select x;
            categories = q.ToList<object>();
            return categories;


        }
        public List<object> getCatItems(int category)
        {
            List<object> catItems = new List<object>();
            var q = (from x in r.Stationeries
                     where x.CategoryID == category
                     select x);
            catItems = q.ToList<object>();
            return catItems;
        }

        public List<Object> getSuppliers()
        {
            List<Object> supplist = new List<object>();
            var q = from s in r.Suppliers
                    select s;
            supplist = q.ToList<Object>();
            return supplist;

        }
        //for maintain stationery items
        //public List<object> getStatList() 
        //{
        //    StationeryInventoryEntities1 se= new StationeryInventoryEntities1();
        //    var statlist = (from s in se.Stationeries
        //                    select new s { });
        //    return statlist.ToList();
        //}


        //public List<object> button_select()
        //{
        //    //List<object> sup_details = new List<object>();
        //    //string ItemNumber = ((Label)GridView1.Rows[te].FindControl("Label1")).Text;
        //    //StationeryInventoryEntities st = new StationeryInventoryEntities();
        //    //var m = (from u in st.Stationeries
        //    //         where u.ItemCode == ItemNumber
        //    //         select u).Single();

        //}
    }
}
